<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-hemisu.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-hemisu.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-hemisu.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="hemisu">










<meta name="description" content="Just do...">
<meta name="keywords" content="web, 前端, 生活, 分享">
<meta property="og:type" content="website">
<meta property="og:title" content="何米酥`s Blog">
<meta property="og:url" content="http://www.hemisu.com/page/19/index.html">
<meta property="og:site_name" content="何米酥`s Blog">
<meta property="og:description" content="Just do...">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="何米酥`s Blog">
<meta name="twitter:description" content="Just do...">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://www.hemisu.com/page/19/">





  <title>何米酥`s Blog</title>
  








  <!-- Hotjar Tracking Code for www.hemisu.com -->
  <script>
      (function(h,o,t,j,a,r){
          h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
          h._hjSettings={hjid:1933736,hjsv:6};
          a=o.getElementsByTagName('head')[0];
          r=o.createElement('script');r.async=1;
          r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
          a.appendChild(r);
      })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
  </script>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">何米酥`s Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">EFE</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/17/54/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/17/54/" itemprop="url">PAT B1008</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-17T15:17:00+00:00">
                2017-01-17
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>一个数组A中存有N（N&gt;0）个整数，在不允许使用另外数组的前提下，将每个整数循环向右移M（M&gt;=0）个位置，即将A中的数据由（A0 A1……AN-1）变换为（AN-M …… AN-1 A0 A1……AN-M-1）（最后M个数循环移至最前面的M个位置）。如果需要考虑程序移动数据的次数尽量少，要如何设计移动的方法？</p>
<p>输入格式：每个输入包含一个测试用例，第1行输入N ( 1&lt;=N&lt;=100)、M（M&gt;=0）；第2行输入N个整数，之间用空格分隔。</p>
<p>输出格式：在一行中输出循环右移M位以后的整数序列，之间用空格分隔，序列结尾不能有多余空格。</p>
<p>输入样例：<br>6 2<br>1 2 3 4 5 6<br>输出样例：<br>5 6 1 2 3 4</p>
<pre><code>#include &lt;stdio.h&gt;
int main() {
    int N,M,count = 0;
    int arr[101];
    scanf(&quot;%d%d&quot;, &amp;N, &amp;M);
    for (int i = 0; i &lt; N; i++) {
        scanf(&quot;%d&quot;, &amp;arr[i]);
    }
    M = M%N;//取余 修正
    for (int i = N - M; i &lt; N; i++) {
        printf(&quot;%d&quot;, arr[i]);
        count++;
        if (count &lt; N) {
            printf(&quot; &quot;);
        }
    }
    for (int i = 0; i &lt; N - M; i++) {
        printf(&quot;%d&quot;, arr[i]);
        count++;
        if (count &lt; N) {
            printf(&quot; &quot;);
        }
    }
    return 0;
}
</code></pre><p>另解：</p>
<pre><code>#include &lt;stdio.h&gt;
void reverse(int arr[],int p,int q){
    for (; p &lt; q; p++, q--) {
        int temp = arr[q];
        arr[q] = arr[p];
        arr[p] = temp;
    }
}
int main() {
    int N,M;
    int arr[101];
    scanf(&quot;%d%d&quot;, &amp;N, &amp;M);
    for (int i = 0; i &lt; N; i++) {
        scanf(&quot;%d&quot;, &amp;arr[i]);
    }
    M %= N;//取余 修正
    reverse(arr, 0, N-M-1);
    reverse(arr, N-M, N-1);
    reverse(arr, 0, N-1);
    for (int i = 0; i &lt; N; i++) {
        printf(&quot;%d &quot;,arr[i]);
    }
    return 0;
}
</code></pre><p>算法笔记中利用最大公约数达到最小移动次数的方法：</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;math.h&quot;
#include &quot;string.h&quot;
//#include &quot;iostream&quot;
#include &quot;algorithm&quot;
using namespace std;
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}
int main(){
    int a[110];
    int n, m, temp, pos, next;
    //temp为临时变量，pos存放当前处理的位置，next为下一个要处理的位置
    scanf(&quot;%d%d&quot;, &amp;n, &amp;m);
    for (int i = 0; i &lt; n; i++) {
        scanf(&quot;%d&quot;, &amp;a[i]);
    }
    m = m % n;//修正m
    if (m != 0) {
        int d = gcd(m, n);
        for (int i = n - m; i &lt; n - m + d; i++) {//枚举一个最大公约数的范围
            temp = a[i];//把当前位置元素先拿走
            pos = i;//记录当前要处理的位置
            do{
                //计算下一个要处理的位置
                next = (pos - m + n) % n;
                //如果下一个位置不是初始点
                //则把下一个位置的元素赋值为当前处理位置
                if (next != i) a[pos] = a[next];
                else a[pos] = temp;//把一开始拿走的元素赋值给最后这个空位
                pos = next;//传递位置
            }while(pos != i);//循环位置直到当前处理位置回到初始位置结束
        }
    }
    for (int i = 0 ; i &lt; n; i++) {
        printf(&quot;%d&quot;, a[i]);
        if (i &lt; n -1) {
            printf(&quot; &quot;);
        }
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/17/53/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/17/53/" itemprop="url">PAT B1046</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-17T14:57:37+00:00">
                2017-01-17
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为：每人口中喊出一个数字，同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和，谁就赢了，输家罚一杯酒。两人同赢或两人同输则继续下一轮，直到唯一的赢家出现。</p>
<p>下面给出甲、乙两人的划拳记录，请你统计他们最后分别喝了多少杯酒。</p>
<p>输入格式：</p>
<p>输入第一行先给出一个正整数N（&lt;=100），随后N行，每行给出一轮划拳的记录，格式为：</p>
<p>甲喊 甲划 乙喊 乙划</p>
<p>其中“喊”是喊出的数字，“划”是划出的数字，均为不超过100的正整数（两只手一起划）。</p>
<p>输出格式：</p>
<p>在一行中先后输出甲、乙两人喝酒的杯数，其间以一个空格分隔。</p>
<p>输入样例：<br>5<br>8 10 9 12<br>5 10 5 10<br>3 8 5 12<br>12 18 1 13<br>4 16 12 15<br>输出样例：<br>1 2</p>
<pre><code>#include &lt;stdio.h&gt;
//#include &lt;math.h&gt;
int main() {
    int n, failA = 0, failB = 0;
    scanf(&quot;%d&quot;, &amp;n);
    for (int i = 0; i &lt; n ; i++) {
        int a1, a2, b1, b2;
        scanf(&quot;%d%d%d%d&quot;, &amp;a1, &amp;a2, &amp;b1, &amp;b2);
        if (a1 + b1 == a2 &amp;&amp; a1 + b1 != b2) {//甲猜中
            failB++;
        }else if(a1 + b1 != a2 &amp;&amp; a1 + b1 == b2){
            failA++;
        }
    }
    printf(&quot;%d %d\n&quot;, failA, failB);
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/17/52/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/17/52/" itemprop="url">PAT B1046</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-17T14:57:30+00:00">
                2017-01-17
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <pre><code>#include &lt;stdio.h&gt;
//#include &lt;math.h&gt;
int main() {
    int n, failA = 0, failB = 0;
    scanf(&quot;%d&quot;, &amp;n);
    for (int i = 0; i &lt; n ; i++) {
        int a1, a2, b1, b2;
        scanf(&quot;%d%d%d%d&quot;, &amp;a1, &amp;a2, &amp;b1, &amp;b2);
        if (a1 + b1 == a2 &amp;&amp; a1 + b1 != b2) {//甲猜中
            failB++;
        }else if(a1 + b1 != a2 &amp;&amp; a1 + b1 == b2){
            failA++;
        }
    }
    printf(&quot;%d %d\n&quot;, failA, failB);
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/16/50/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/16/50/" itemprop="url">PAT B1026</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-16T23:58:00+00:00">
                2017-01-16
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>要获得一个C语言程序的运行时间，常用的方法是调用头文件time.h，其中提供了clock()函数，可以捕捉从程序开始运行到clock()被调用时所耗费的时间。这个时间单位是clock tick，即“时钟打点”。同时还有一个常数CLK_TCK，给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数f的运行时间，我们只要在调用f之前先调用clock()，获得一个时钟打点数C1；在f执行完成后再调用clock()，获得另一个时钟打点数C2；两次获得的时钟打点数之差(C2-C1)就是f运行所消耗的时钟打点数，再除以常数CLK_TCK，就得到了以秒为单位的运行时间。</p>
<p>这里不妨简单假设常数CLK_TCK为100。现给定被测函数前后两次获得的时钟打点数，请你给出被测函数运行的时间。</p>
<p>输入格式：</p>
<p>输入在一行中顺序给出2个整数C1和C1。注意两次获得的时钟打点数肯定不相同，即C1 &lt; C2，并且取值在[0, 107]。</p>
<p>输出格式：</p>
<p>在一行中输出被测函数运行的时间。运行时间必须按照“hh:mm:ss”（即2位的“时:分:秒”）格式输出；不足1秒的时间四舍五入到秒。</p>
<p>输入样例：<br>123 4577973<br>输出样例：<br>12:42:59</p>
<pre><code>#include &lt;stdio.h&gt;
int main() {
    int c1,c2;
    scanf(&quot;%d %d&quot;, &amp;c1, &amp;c2);
    int ans = c2 - c1;
    if (ans % 100 &gt;= 50) {
        ans = ans / 100 + 1 ;
    }else{
        ans = ans / 100;
    }
    printf(&quot;%02d:%02d:%02d\n&quot;, ans / 3600, ans % 3600 / 60, ans % 60);
    return 0;
}
</code></pre><p>使用round版本，引入math.h</p>
<pre><code>#include &lt;stdio.h&gt;
#include &lt;math.h&gt;
int main() {
    float c1,c2;
    scanf(&quot;%f %f&quot;, &amp;c1, &amp;c2);
    float ans = (c2 - c1)/100;
    int finalans = (int)round(ans);
    printf(&quot;%02d:%02d:%02d\n&quot;, finalans / 3600, finalans % 3600 / 60, finalans % 60);
    return 0;
}
</code></pre><p>收获：<br>时分秒的输出要保证不足两位时高位用0补充<br>round函数要用到浮点数，不能用int</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/16/49/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/16/49/" itemprop="url">PAT B1016</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-16T22:23:55+00:00">
                2017-01-16
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>正整数A的“DA（为1位整数）部分”定义为由A中所有DA组成的新整数PA。例如：给定A = 3862767，DA = 6，则A的“6部分”PA是66，因为A中有2个6。</p>
<p>现给定A、DA、B、DB，请编写程序计算PA + PB。</p>
<p>输入格式：</p>
<p>输入在一行中依次给出A、DA、B、DB，中间以空格分隔，其中0 &lt; A, B &lt; 1010。</p>
<p>输出格式：</p>
<p>在一行中输出PA + PB的值。</p>
<p>输入样例1：<br>3862767 6 13530293 3<br>输出样例1：<br>399<br>输入样例2：<br>3862767 1 13530293 8<br>输出样例2：<br>0</p>
<pre><code>#include &lt;stdio.h&gt;
int main() {
    long long a,b;
    int da,db,pa,pb;
    scanf(&quot;%lld %d %lld %d&quot;, &amp;a, &amp;da, &amp;b, &amp;db);
    pa = pb = 0;
    while (a) {
        if (a % 10 == da) {
            pa = pa * 10 + da;
        }
        a /= 10;
    }
    while (b) {
        if (b % 10 == db) {
            pb = pb * 10 + db;
        }
        b /= 10;
    }
    printf(&quot;%d&quot;,pa+pb);
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/16/47/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/16/47/" itemprop="url">PAT B1011</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-16T16:02:21+00:00">
                2017-01-16
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>给定区间[-231, 231]内的3个整数A、B和C，请判断A+B是否大于C。</p>
<p>输入格式：</p>
<p>输入第1行给出正整数T(&lt;=10)，是测试用例的个数。随后给出T组测试用例，每组占一行，顺序给出A、B和C。整数间以空格分隔。</p>
<p>输出格式：</p>
<p>对每组测试用例，在一行中输出“Case #X: true”如果A+B&gt;C，否则输出“Case #X: false”，其中X是测试用例的编号（从1开始）。</p>
<p>输入样例：<br>4<br>1 2 3<br>2 3 4<br>2147483647 0 2147483646<br>0 -2147483648 -2147483647<br>输出样例：<br>Case #1: false<br>Case #2: true<br>Case #3: true<br>Case #4: false</p>
<pre><code>#include &lt;stdio.h&gt;
int main() {
    int T,tcase = 1;
    scanf(&quot;%d&quot;,&amp;T);//输入数据组
    while (T--) {
        long long a,b,c;
        scanf(&quot;%lld%lld%lld&quot;,&amp;a,&amp;b,&amp;c);
        if (a + b &gt; c) {
            printf(&quot;Case #%d: true\n&quot;,tcase++);
        }else{
            printf(&quot;Case #%d: false\n&quot;,tcase++);
        }
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/16/46/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/16/46/" itemprop="url">PAT B1005</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-16T01:08:00+00:00">
                2017-01-16
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里，情况稍微有些复杂。</p>
<p>当我们验证卡拉兹猜想的时候，为了避免重复计算，可以记录下递推过程中遇到的每一个数。例如对n=3进行验证的时候，我们需要计算3、5、8、4、2、1，则当我们对n=5、8、4、2进行验证的时候，就可以直接判定卡拉兹猜想的真伪，而不需要重复计算，因为这4个数已经在验证3的时候遇到过了，我们称5、8、4、2是被3“覆盖”的数。我们称一个数列中的某个数n为“关键数”，如果n不能被数列中的其他数字所覆盖。</p>
<p>现在给定一系列待验证的数字，我们只需要验证其中的几个关键数，就可以不必再重复验证余下的数字。你的任务就是找出这些关键数字，并按从大到小的顺序输出它们。</p>
<p>输入格式：每个测试输入包含1个测试用例，第1行给出一个正整数K(&lt;100)，第2行给出K个互不相同的待验证的正整数n(1&lt;n&lt;=100)的值，数字间用空格隔开。</p>
<p>输出格式：每个测试用例的输出占一行，按从大到小的顺序输出关键数字。数字间用1个空格隔开，但一行中最后一个数字后没有空格。</p>
<p>输入样例：<br>6<br>3 5 6 7 8 11<br>输出样例：<br>7 6</p>
<pre><code>#include &lt;stdio.h&gt;
int main() {
    int num[101];
    int i, k, n, len=0;
    for(i = 0; i &lt; 101; i ++) {
        num[i] = -1;
    }
    scanf(&quot;%d&quot;, &amp;k);
    for(i = 0; i &lt; k; i ++) {
        scanf(&quot;%d&quot;, &amp;n);
        num[n] = 0;
    }
    for(i = 0; i &lt; 101; i ++) {
        if(num[i] != 0) {
            continue;
        }
        n = i;
        while(n != 1) {
            if(n % 2 == 0) {
                n = n / 2;
                if(n &lt;= 100) {
                    num[n] = 1;
                }
            } else {
                n = 3 * n + 1;
                n = n / 2;
                if(n &lt;= 100) {
                    num[n] = 1;
                }
            }
        }
    }
    for (i = 100; i; i--) {
        if(num[i] == 0)len++;
    }
    for(i = 100; i ; i --) {
        if(num[i] == 0) {
            if (--len) {
                printf(&quot;%d &quot;,i);
            }else{
                printf(&quot;%d&quot;,i);
                break;
            }
        }
    }
}
</code></pre><p>2月10日更新：（学习散列后）</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;math.h&quot;
#include &quot;string.h&quot;
#include &quot;algorithm&quot;
using namespace std;
bool cmp(int a, int b){
    return a &gt; b;
}
int main(){
    int n, m, a[110];
    scanf(&quot;%d&quot;, &amp;n);
    bool hashTable[10000] = {0};
    for (int i = 0 ; i &lt; n; i++) {
        scanf(&quot;%d&quot;, &amp;a[i]);
        m = a[i];
        while (m != 1) {
            if (m % 2 == 1) m = (3 * m +1) / 2;
            else m = m/2;
            hashTable[m] = true;
        }
    }
    int cnt = 0;//计数『关键数』的个数
    for (int i = 0; i &lt; n; i++) {
        if (hashTable[a[i]] == false) {
            cnt++;
        }
    }
    sort(a,a+n,cmp);
    for (int i = 0; i &lt; n; i++) {
        if (hashTable[a[i]] == false) {
            printf(&quot;%d&quot;, a[i]);
            cnt--;
            if (cnt) {
                printf(&quot; &quot;);
            }
        }
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/15/45/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/15/45/" itemprop="url">PAT B1004</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-15T23:28:00+00:00">
                2017-01-15
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>读入n名学生的姓名、学号、成绩，分别输出成绩最高和成绩最低学生的姓名和学号。</p>
<p>输入格式：每个测试输入包含1个测试用例，格式为</p>
<p>  第1行：正整数n<br>  第2行：第1个学生的姓名 学号 成绩<br>  第3行：第2个学生的姓名 学号 成绩<br>  … … …<br>  第n+1行：第n个学生的姓名 学号 成绩<br>其中姓名和学号均为不超过10个字符的字符串，成绩为0到100之间的一个整数，这里保证在一组测试用例中没有两个学生的成绩是相同的。<br>输出格式：对每个测试用例输出2行，第1行是成绩最高学生的姓名和学号，第2行是成绩最低学生的姓名和学号，字符串间有1空格。</p>
<p>输入样例：<br>3<br>Joe Math990112 89<br>Mike CS991301 100<br>Mary EE990830 95<br>输出样例：<br>Mike CS991301<br>Joe Math990112</p>
<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
struct student{
    char name[11];
    char id[11];
    int score;
} *ps;
int main(){
    int i,n;
    int max = -1 , min = 101;
    int cmax = 1, cmin = 1;

    scanf(&quot;%d&quot;,&amp;n);
    if (n &lt; 0) {
        return 0;
    }

    ps = (struct student *)malloc(n * sizeof(struct student));
    if (ps == NULL) {
        return 0;
    }

    for( i =0; i&lt;n ; i++){
        scanf(&quot;%s %s %d&quot;,ps[i].name,ps[i].id,&amp;(ps[i].score));
    }
    for (i = 0 ; i&lt;n; i++) {
        if (ps[i].score &lt; min) {
            cmin = i;
            min = ps[i].score;
        }
        if (ps[i].score &gt; max) {
            cmax = i;
            max = ps[i].score;
        }
    }

    printf(&quot;%s %s\n&quot;,ps[cmax].name,ps[cmax].id);
    printf(&quot;%s %s\n&quot;,ps[cmin].name,ps[cmin].id);
    return 0;
}
</code></pre><p>算法笔记代码：</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
struct{
    char name[15];
    char stuid[15];
    int score;
} temp, ansmax, ansmin;
int main(){
    int max = -1,min = 101;
    int n;
    scanf(&quot;%d&quot;, &amp;n);
    for (int i = 0 ; i &lt; n; i++) {
        scanf(&quot;%s%s%d&quot;, temp.name, temp.stuid, &amp;temp.score);
        if (temp.score &gt; max) {
            ansmax = temp;
            max = temp.score;
        }
        if (temp.score &lt; min) {
            ansmin = temp;
            min = temp.score;
        }
    }
    printf(&quot;%s %s\n&quot;, ansmax.name, ansmax.stuid);
    printf(&quot;%s %s&quot;, ansmin.name, ansmin.stuid);
    return 0;
}
</code></pre><p>收获：<br>结构体直接赋值给ansmax,ansmin避免字符串的操作。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/15/43/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/15/43/" itemprop="url">递归应用 全排列</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-15T22:12:54+00:00">
                2017-01-15
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <pre><code>#include &lt;stdio.h&gt;
//#include &lt;string.h&gt;
//#include &lt;algorithm&gt;
//using namespace std;
const int maxn = 4;
int n,
P[maxn],
hashTable[maxn] = {false};
void generateP(int index){
    if(index == n + 1) {
        for (int i = 1; i &lt;= n; i++) {
            printf(&quot;%d&quot;, P[i]);
        }
        printf(&quot;\n&quot;);
        return;
    }
    for (int x = 1; x &lt;= n; x++) {
        if(hashTable[x] == false){
            P[index] = x;
            hashTable[x] = true;
            generateP(index + 1);
            hashTable[x] = false;
        }
    }
}
int main(){
    n = 3;
    generateP(1);
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/04/41/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/04/41/" itemprop="url">PAT B1003</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-04T15:31:00+00:00">
                2017-01-04
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <ol start="1003">
<li>我要通过！(20)<br>“答案正确”是自动判题系统给出的最令人欢喜的回复。本题属于PAT的“答案正确”大派送 —— 只要读入的字符串满足下列条件，系统就输出“答案正确”，否则输出“答案错误”。</li>
</ol>
<p>得到“答案正确”的条件是：</p>
<ol>
<li>字符串中必须仅有P, A, T这三种字符，不可以包含其它字符；</li>
<li>任意形如 xPATx 的字符串都可以获得“答案正确”，其中 x 或者是空字符串，或者是仅由字母 A 组成的字符串；</li>
<li>如果 aPbTc 是正确的，那么 aPbATca 也是正确的，其中 a, b, c 均或者是空字符串，或者是仅由字母 A 组成的字符串。</li>
</ol>
<p>现在就请你为PAT写一个自动裁判程序，判定哪些字符串是可以获得“答案正确”的。<br>输入格式： 每个测试输入包含1个测试用例。第1行给出一个自然数n (&lt;10)，是需要检测的字符串个数。接下来每个字符串占一行，字符串长度不超过100，且不包含空格。</p>
<p>输出格式：每个字符串的检测结果占一行，如果该字符串可以获得“答案正确”，则输出YES，否则输出NO。</p>
<p>输入样例：<br>8<br>PAT<br>PAAT<br>AAPATAA<br>AAPAATAAAA<br>xPATx<br>PT<br>Whatever<br>APAAATAA<br>输出样例：<br>YES<br>YES<br>YES<br>YES<br>NO<br>NO<br>NO<br>NO</p>
<pre><code>#include &lt;string.h&gt;
#include &lt;stdio.h&gt;
int main(){
    char str[101];
    int j,n;
    int count_P,count_A,count_T,pos_P,pos_T;
    scanf(&quot;%d\n&quot;,&amp;n);
    while( n &gt; 0 ){
        gets(str);
        count_P = count_A = count_T = pos_P = pos_T =0;
        for(j = 0; j&lt;strlen(str);j++){
            if(str[j] == &apos;P&apos;){
                count_P++;
                pos_P = j;
            }
            if(str[j] == &apos;A&apos;)count_A++;
            if(str[j] == &apos;T&apos;){
                count_T++;
                pos_T = j;
            }
        }
        if(count_P+count_A+count_T != strlen(str) ||
            pos_T-pos_P&lt;=1 ||count_P&gt;1 ||count_T&gt;1||
            pos_P*(pos_T-pos_P-1) != strlen(str)-pos_T-1){
                printf(&quot;NO\n&quot;);
        }else{
            printf(&quot;YES\n&quot;);
        }
        n--;
    }
    return 0;
}
</code></pre><p>收获<br>这题是真的不会了：D 受到打击几天没写，答案百度来的。可用。</p>
<p>算法笔记上的：</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;math.h&quot;
#include &quot;string.h&quot;
//#include &quot;iostream&quot;
//#include &quot;algorithm&quot;
//using namespace std;
int main(){
    int T;
    scanf(&quot;%d&quot;, &amp;T);
    while (T--) {
        char str[110];
        scanf(&quot;%s&quot;, str);
        int len = (int)strlen(str);
        //分别代表P,T,除PAT以外的字符个数
        int num_p = 0, num_t = 0, other = 0;
        int loc_p = -1, loc_t = -1;//分别代表p的位置，t的位置
        for (int i = 0; i &lt; len ; i++) {
            if (str[i] == &apos;P&apos;) {
                num_p++;
                loc_p = i;
            }else if (str[i] == &apos;T&apos;){
                num_t++;
                loc_t = i;
            }else if (str[i] != &apos;A&apos;){
                other++;
            }
        }
        //如果P的个数不为1，或者T的个数不为1
        //或者存在PAT以外的字符，或者P和T之间没有字符
        if ((num_p != 1) || (num_t != 1) || (other != 0) || (loc_t - loc_p &lt;= 1)) {
            printf(&quot;NO\n&quot;);
            continue;
        }
        //x,y,z
        int x = loc_p, y = loc_t - loc_p - 1, z = len - loc_t -1;
        if (z - x * (y - 1) == x) {
            printf(&quot;YES\n&quot;);
        }else{
            printf(&quot;NO\n&quot;);
        }
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/18/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/18/">18</a><span class="page-number current">19</span><a class="page-number" href="/page/20/">20</a><a class="page-number" href="/page/21/">21</a><a class="extend next" rel="next" href="/page/20/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="何米酥">
            
              <p class="site-author-name" itemprop="name">何米酥</p>
              <p class="site-description motion-element" itemprop="description">Just do...</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">202</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">78</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/hemisu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/hemisu" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-globe"></i>知乎</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">何米酥</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
